﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nage.Examples.Rastrigin.Solution;
using Nage.Examples.RastriginIsland.Topologies;
using Utils.Logger;

namespace Nage.Examples.RastriginIsland
{
    class Program
    {
        static void Main(string[] args)
        {
            int islandsAmount = 2; 
            int populationSize = 100; 
            double mutationRate = 0.1;
            double delta = 0.5;
            double crossoverRate = 0.8;
            int stepCount = 2000;
            int migrateAfter = 5;

            RastriginProblemIsland problem = new RastriginProblemIsland(islandsAmount, populationSize, mutationRate, delta, crossoverRate, stepCount, migrateAfter);
            problem.StepCompleted += ProblemStepCompleted;
            problem.Solve();
        }

        static void ProblemStepCompleted(int generation, ITopology<Coordinates> topology)
        {
            WriteLine("======== Generation #{0} ========", generation);
            int i = 1;
            foreach (TopologyNode<Coordinates> node in topology)
            {
                WriteLine("--- Island #{0} ---", i);
                foreach (Coordinates coords in node.Population)
                {
                    WriteLine(coords);
                }
                i++;
            }
        }

        #region WriteLine
        static void WriteLine(object pattern)
        {
            WriteLine(pattern.ToString(), new object[] { });
        }

        static void WriteLine(String pattern, params object[] paramArr)
        {
            //Console.WriteLine(pattern, paramArr);
            CLogger.LogInfo(pattern, paramArr);
        } 
        #endregion
    }
}
